package com.hyh.prize.controller;

import com.hyh.prize.service.TabGgcardEncashService;
import com.lww.springcloudapi.entity.TabGgcardEncash;
import com.lww.springcloudapi.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 刮刮卡兑奖日志表 前端控制器
 * </p>
 *
 * @author SHEN
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/admin/prize/encash/")
@Api(tags = "兑奖日志模块")
public class TabGgcardEncashController {

    @Resource
    private TabGgcardEncashService tabGgcardEncashService;

    @GetMapping("get/{id}")
    @ApiOperation(value = "根据id查询兑换日志")
    public Result getGG(@PathVariable Long id){
        TabGgcardEncash byId = tabGgcardEncashService.getById(id);
        return Result.ok(byId);
    }

    @PostMapping("list/{current}/{size}")
    @ApiOperation(value = "分页查询兑换日志")
    public Result getList(@PathVariable long current,
                          @PathVariable long size,
                          @RequestBody(required = false) TabGgcardEncash tabGgcardEncash) {
//        Page<TabGgcardEncash> page = new Page(current, size);
//        QueryWrapper<TabGgcardEncash> queryWrapper = new QueryWrapper<>();
//        if (tabGgcardEncash.getPrizelevel() != null && tabGgcardEncash.getPrizelevel() > 0) {
//            queryWrapper.eq("PRIZELEVEL", tabGgcardEncash.getPrizelevel());
//        }
//        if (tabGgcardEncash.getEncashstate() != null && !tabGgcardEncash.getEncashstate().equals("0")) {
//            queryWrapper.eq("ENCASHSTATE", tabGgcardEncash.getEncashstate());
//        }
//        Page<TabGgcardEncash> tabGgcardEncashPage = tabGgcardEncashService.page(page, queryWrapper);

        return tabGgcardEncashService.getList(current,size,tabGgcardEncash);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加兑换记录")
    public Result addPrize(@RequestBody TabGgcardEncash tabGgcardEncash) {
        boolean save = tabGgcardEncashService.save(tabGgcardEncash);
        if (save) {
            return Result.ok();
        }
        return Result.fail();
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation(value = "删除兑换记录")
    public Result deleteEncash(@PathVariable long id) {
        System.out.println(id);
        tabGgcardEncashService.removeById(id);
        return Result.ok();
    }


    @PostMapping("update")
    @ApiOperation(value = "修改营兑换记录")
    public Result updateEncash(@RequestBody TabGgcardEncash tabGgcardEncash) {
        boolean update = tabGgcardEncashService.updateById(tabGgcardEncash);
        if (update) {
            return Result.ok();
        }
        return Result.fail();
    }


}

